package com.chinatechstar.admin.controller;

import com.chinatechstar.admin.entity.Dept;
import com.chinatechstar.admin.entity.JsonObj;
import com.chinatechstar.admin.service.DeptInfoService;
import com.chinatechstar.admin.vo.DeptVo;
import com.chinatechstar.admin.vo.SysMenuVO;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 科室： dept_info
 */
@Api(value = "科室的控制层", tags = {"科室信息"})
@RestController
@RequestMapping("/dept")
public class DeptInfoController {

    @Autowired
    private DeptInfoService deptInfoService;

    /**
     * 添加科室
     */
    @PostMapping("/add")
    public JsonObj add(@RequestBody Dept dept) {
        return deptInfoService.add(dept);
    }

    /**
     * 删除科室
     */
    @GetMapping("/del")
    public JsonObj del(@RequestParam String id) {
        return deptInfoService.del(id);
    }

    /**
     * 修改科室
     */
    @PostMapping("/edit")
    public JsonObj edit(@RequestBody Dept dept) {
        return deptInfoService.edit(dept);
    }


    /**
     * 查询科室（单个）
     */
    @GetMapping("/selById")
    public JsonObj selById(@RequestParam String id) {
        Map<String, Object> map = deptInfoService.selById(id);
        return JsonObj.success(map);
    }

    @GetMapping(path = "/queryDept")
    public ListResult<Object> queryDept(DeptVo deptVo) {
        Map<String, Object> data = deptInfoService.queryDept(deptVo);
        return ResultBuilder.buildListSuccess(data);
    }

    /**
     * 查询机构下的科室列表
     */
    @GetMapping(path = "/getDeptList")
    public ListResult<Object> getDeptList(@RequestParam String orgId) {
        LinkedHashMap<String, Object> data = deptInfoService.getDeptList(orgId);
        return ResultBuilder.buildListSuccess(data);
    }

}